﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.services {
    import flash.events.*;
    import flash.utils.*;
    import flash.media.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;

    public class SoundService extends Actor {

        private var _volume:Number = 1
        private var _muted:Boolean;// = false
        private var _effectsMuted:Boolean;
        private var _musicMuted:Boolean;
        private var _sounds:Dictionary;
        private var _currentBackgroundMusic:SoundChannel;
        private var _permanentBackgroundEffect:SoundChannel;

        public function SoundService(){
            this._sounds = new Dictionary();
            super();
        }
        public function playSound(_arg1:String, _arg2:int=1, _arg3:Number=1):SoundChannel{
            var _local4:SoundChannel = this.getSound(_arg1).play(_arg2);
            _local4.soundTransform = new SoundTransform(_arg3);
            return (_local4);
        }
        private function getSound(_arg1:String):SoundVO{
            this._sounds[_arg1] = ((this._sounds[_arg1]) || (new SoundVO(_arg1)));
            return (SoundVO(this._sounds[_arg1]));
        }
        public function get volume():Number{
            return (this._volume);
        }
        public function set volume(_arg1:Number):void{
            this._volume = _arg1;
            this.updateVolume();
        }
        public function get muted():Boolean{
            return (this._muted);
        }
        public function set muted(_arg1:Boolean):void{
            this._muted = _arg1;
            this.updateVolume();
        }
        private function updateVolume():void{
            var _local1:Number = (this._muted) ? 0 : this._volume;
            SoundMixer.soundTransform = new SoundTransform(_local1);
        }
        public function get effectsMuted():Boolean{
            return (this._effectsMuted);
        }
        public function set effectsMuted(_arg1:Boolean):void{
            this._effectsMuted = _arg1;
            dispatch(new Event(EventConstants.EFFECT_SOUND_STATE_CHANGE));
        }
        public function get musicMuted():Boolean{
            return (this._musicMuted);
        }
        public function set musicMuted(_arg1:Boolean):void{
            this._musicMuted = _arg1;
            dispatch(new Event(EventConstants.MUSIC_SOUND_STATE_CHANGE));
            var _local2:int = (this._musicMuted) ? 0 : 1;
            ((this._currentBackgroundMusic) && ((this._currentBackgroundMusic.soundTransform = new SoundTransform(_local2))));
            ((this._permanentBackgroundEffect) && ((this._permanentBackgroundEffect.soundTransform = new SoundTransform((_local2 * 0.5)))));
        }
        public function set currentBackgroundMusic(_arg1:SoundChannel):void{
            this._currentBackgroundMusic = _arg1;
        }
        public function set permanentBackgroundEffect(_arg1:SoundChannel):void{
            this._permanentBackgroundEffect = _arg1;
        }

    }
}//package net.wooga.pets.services 

import flash.events.*;
import flash.net.*;
import flash.media.*;

class SoundVO {

    private var _sound:Sound;

    public function SoundVO(_arg1:String){
        this._sound = new Sound();
        var _local2:URLRequest = new URLRequest(_arg1);
        this._sound.addEventListener(IOErrorEvent.IO_ERROR, this.ioErrorHandler);
        this._sound.load(_local2);
    }
    private function ioErrorHandler(_arg1:IOErrorEvent):void{
        log(("e " + _arg1));
    }
    public function play(_arg1:int=1):SoundChannel{
        if (_arg1 == -1){
            _arg1 = int.MAX_VALUE;
        };
        var _local2:SoundChannel = this._sound.play(0, _arg1);
        if (!_arg1){
            _local2.stop();
        };
        return (_local2);
    }
    public function get channel():SoundChannel{
        return (this.channel);
    }

}
